home *** CD-ROM | disk | FTP | other *** search
- /* Iconmanager +10 サンプル */
- /* 1992 by H.Ogasawara (COR.) */
-
- #include <corlib.h>
- #include <winop.h>
-
- /* 手抜きプログラムだけどサンプルです */
-
- #define HSIZE 80
- #define VSIZE 80
- #define XOFFSET 2
- #define YOFFSET 2
-
- #define C(msg) {ConsoleOpen();ConsolePrint(msg);}
-
- typedef struct icontbl {
- WindowID wp;
- int x, y, h;
- struct icontbl *next;
- } IconTbl;
-
- IconTbl *Top= NULL;
- int GlobalX= 1;
- int WindowHeapSize= 1024;
-
- /* テーブル追加 */
- IconTbl *
- alloc_tbl( wp, x, y, h )
- WindowID wp;
- {
-
- IconTbl *it;
- if( it= (IconTbl*)WindowMemoryAlloc( sizeof(IconTbl) ) ){
- it->next= Top;
- Top= it;
- it->wp= wp;
- it->x= x;
- it->y= y;
- it->h= h;
- return it;
- }
- return NULL;
- }
-
- /* テーブル開放 */
- free_tbl( wp )
- WindowID wp;
- {
- IconTbl *it= Top,
- **pt= &Top;
- for(; it ; pt= &it->next, it= it->next ){
- if( wp == it->wp ){
- *pt= it->next;
- WindowMemoryFree( it );
- break;
- }
- }
- }
-
- /* テーブル解除 */
- free_tbl_all()
- {
- IconTbl *it= Top, *pt;
- for(; it ; it= pt ){
- pt= it->next;
- WindowMemoryFree( it );
- }
- }
-
- /* 空き場所チェック */
- check_tbl_width( x, h )
- {
- IconTbl *it= Top;
- for(; it ; it= it->next ){
- if( (it->x > x && it->x < x+h) ||
- (it->x+it->h > x && it->x+it->h < x+h) )
- return FALSE;
- }
- return TRUE;
- }
-
- /* 空き場所を探す */
- search_tbl_position( h )
- {
- IconTbl *it= Top;
- for(; it ; it= it->next ){
- if( check_tbl_width( it->x+it->h+ 2 , h ) )
- return it->x+it->h+2;
- }
- return XOFFSET;
- }
-
- /* アイコン化ルーチン */
- IconifyExec( wp, h, v, exec, px, py )
- WindowID wp;
- int h, v;
- int (*exec)();
- int *px, *py;
- {
- int x;
- C( "sono1\r\n" );
- if( x= search_tbl_position( h ) ){
- C( "sono2\r\n" );
- *px= x;
- *py= YOFFSET;
- C( "sono3\r\n" );
- alloc_tbl( wp, *px, *py, h );
- C( "sono4\r\n" );
- }
- return FALSE;
- }
-
- /* アイコンマウスルーチン */
- IconMouseExec( wp, info, f )
- WindowID wp;
- EventInfo *info;
- int *f;
- {
- *f= TRUE;
- free_tbl( wp );
- return FALSE;
- }
-
- IconManagerInit()
- {
- IconMan *ip;
- if( !WindowGetCommon( "IconManExec", 0 ) ){
- if( ip= WindowGetCommon( "IconManExec", sizeof(IconMan) ) ){
- ip->iconifyexec= IconifyExec;
- ip->iconmouseexec= IconMouseExec;
- }
- return TRUE;
- }else{
- ConsoleOpen();
- ConsolePrint( "iconman:すでに他のiconmanが存在します\r\n" );
- return FALSE;
- }
- }
-
- Exec( wp, info )
- WindowID wp;
- EventInfo *info;
- {
- DrawBuf dbuf[1];
- switch( info->option ){
- case EventRedraw:
- DrawSetClear( dbuf, 1 );
- WindowDraw( wp, dbuf, 1 );
- return TRUE;
- case EventClose: /* マネージャの介入を解除 */
- WindowResetCommon( "IconManExec" );
- free_tbl_all();
- return FALSE;
- }
- return FALSE;
- }
-
- WindowMain( argc, argv )
- char **argv;
- {
- /* サンプルなので、手抜きして MgLIB を使ってます */
- if( IconManagerInit() )
- MgWindowDefaultOpenArgs( 10, 10, HSIZE, VSIZE,
- "IconMan", argc, argv, 0, Exec );
- else
- WindowSendSignal( WindowProcessID, SignalKill, 0 );
- }
-
-